test(pt-expt): add .pte and .pt2 tests for dp convert-backend#5384
test(pt-expt): add .pte and .pt2 tests for dp convert-backend#5384wanghan-iapcm wants to merge 2 commits intodeepmodeling:masterfrom
Conversation
Add pt_expt backend (.pte/.pt2) to the parameterized extensions in test_models.py to verify convert-backend works for the new exportable formats. The fparam_aparam model (1 atom type) is switched from type_one_side=False to type_one_side=True (with ndim 2→1), which is equivalent for single-type models but enables pt_expt export. Models with type_one_side=False and multiple types (se_e2_a, se_e2_r) are skipped for .pte/.pt2 as make_fx cannot trace data-dependent indexing in NetworkCollection(ndim=2).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdates test configurations and the test suite to add pt-expt backend support ( Changes
Sequence Diagram(s)sequenceDiagram
participant TestRunner
participant TestCase as Case.get_model()
participant Torch as torch
participant ModelLoader
TestRunner->>TestCase: setUpClass()
TestCase->>Torch: check INSTALLED_PT_EXPT
alt pt-expt supported
TestRunner->>Torch: torch.set_default_device(None)
TestRunner->>ModelLoader: load model `.pt2`/`.pte`
ModelLoader-->>TestRunner: model object
TestRunner->>Torch: restore previous default device
else not supported
TestRunner->>TestRunner: skip pt-expt tests
end
TestRunner->>ModelLoader: run descriptor & fitting tests (with updated YAML params)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
source/tests/infer/test_models.py (1)
42-45: Prefer deriving the pt_expt skip from fixture metadata.The hard-coded
("se_e2_a", "se_e2_r")list will stay stale the next time a fixture is made exportable. The fixture already carriesmodel_def_script.descriptor.type_one_side, so reading the skip condition fromcasewould keep this gate aligned with the actual model data instead of the testcase key.♻️ Suggested refactor
`@classmethod` def setUpClass(cls) -> None: key, extension = cls.param if extension in (".pte", ".pt2") and not INSTALLED_PT_EXPT: raise unittest.SkipTest("pt_expt backend not installed") - if key in ("se_e2_a", "se_e2_r") and extension in (".pte", ".pt2"): + case = get_cases()[key] + descriptor = (case.model_def_script or {}).get("descriptor", {}) + if ( + extension in (".pte", ".pt2") + and descriptor.get("type") in {"se_e2_a", "se_e2_r"} + and not descriptor.get("type_one_side", False) + ): raise unittest.SkipTest( "type_one_side=False is not supported for pt_expt export" ) if key == "se_e2_r" and extension == ".pth": raise unittest.SkipTest( "se_e2_r type_one_side is not supported for PyTorch models" ) - cls.case = get_cases()[key] + cls.case = case🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@source/tests/infer/test_models.py` around lines 42 - 45, Replace the hard-coded key check with a metadata-driven condition: instead of testing if key in ("se_e2_a", "se_e2_r"), read the fixture's descriptor via the test case (e.g., case.model_def_script.descriptor.type_one_side) and if that value is False and extension is in (".pte", ".pt2") raise unittest.SkipTest; update the conditional that currently uses variables key and extension to use case.model_def_script.descriptor.type_one_side for the gate so the skip stays in sync with fixture metadata.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@source/tests/infer/test_models.py`:
- Around line 42-45: Replace the hard-coded key check with a metadata-driven
condition: instead of testing if key in ("se_e2_a", "se_e2_r"), read the
fixture's descriptor via the test case (e.g.,
case.model_def_script.descriptor.type_one_side) and if that value is False and
extension is in (".pte", ".pt2") raise unittest.SkipTest; update the conditional
that currently uses variables key and extension to use
case.model_def_script.descriptor.type_one_side for the gate so the skip stays in
sync with fixture metadata.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 75ef918e-5c9d-4fdd-a70c-1ed85d0f074f
📒 Files selected for processing (4)
source/tests/infer/fparam_aparam-testcase.yamlsource/tests/infer/fparam_aparam.yamlsource/tests/infer/fparam_aparam_default.yamlsource/tests/infer/test_models.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5384 +/- ##
==========================================
- Coverage 82.38% 80.44% -1.95%
==========================================
Files 812 814 +2
Lines 83611 84438 +827
Branches 4091 4050 -41
==========================================
- Hits 68882 67922 -960
- Misses 13508 15292 +1784
- Partials 1221 1224 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tests/pt/__init__.py may set a fake default device for CPU fallback, which poisons AOTInductor compilation. Temporarily clear the default device before converting to .pt2, matching the pattern used in test_change_bias.py.
Summary
.pteand.pt2to parameterized extensions intest_models.pyto verifyconvert-backendworks for the pt_expt exportable formatsfparam_aparammodel (1 atom type) fromtype_one_side=FalsetoTrue(withndim2→1), which is equivalent for single-type models but enables pt_expt exportse_e2_a/se_e2_rfor.pte/.pt2—type_one_side=Falsewith multiple types triggersGuardOnDataDependentSymNodeinmake_fx(data-dependent indexing inNetworkCollection(ndim=2))test_descriptorandtest_fitting_last_layerfor.pte/.pt2(not implemented in pt_exptDeepEval)Test plan
python -m pytest source/tests/infer/test_models.py -v— 55 passed, 67 skippedpython -m pytest source/tests/infer/test_models.py -v -k "pte or pt2"— 12 passed (fparam_aparam), rest skipped.pb/.pthtests unaffectedSummary by CodeRabbit